package com.bw.liveplay.common.mvvm.adapter

import android.widget.ImageView
import android.widget.TextView
import com.bw.liveplay.R
import com.bw.liveplay.common.entity.FeedEntity
import com.bw.liveplay.common.entity.HomeFeedEntity
import com.bw.liveplay.common.network.LoadImage
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer

/**
 * @author KK
 * @description:
 * @date :2021/11/10 13:25
 *
 */
class HomeListAdapter : BaseQuickAdapter<FeedEntity, BaseViewHolder>(R.layout.item_homelist) {

    init {
        addChildClickViewIds(R.id.item_homelist_love)
        addChildClickViewIds(R.id.item_homelist_cai)
        addChildClickViewIds(R.id.item_homelist_ll)
    }
    override fun convert(holder: BaseViewHolder, item : FeedEntity) {

        val gsy :StandardGSYVideoPlayer = holder.getView(R.id.item_homelist_gsy)
        val img :ImageView = holder.getView(R.id.item_homelist_userimg)
        val username :TextView = holder.getView(R.id.item_homelist_username)
        val comment :TextView = holder.getView(R.id.item_homelist_comment)
        val dz :TextView = holder.getView(R.id.item_homelist_dz)
        val xx :TextView = holder.getView(R.id.item_homelist_xx)
        val fx :TextView = holder.getView(R.id.item_homelist_fx)
        var avatar = item.author!!.avatar
        var commentCount = item.author!!.commentCount
        var history = item.author!!.historyCount
        var favoriteCount = item.author!!.favoriteCount
        if (avatar != null) {
            LoadImage.loadMathImg(avatar,img)//头像
        }

        username.setText(item.author!!.name)//作者名字
        comment.setText(item.feeds_text)//视频名称
        xx.setText(""+commentCount)//评论数
        dz.setText(""+history)//点赞数
        fx.setText(""+favoriteCount)//分享数
        gsy.setUp(item.url,false,"视频")//视频
        gsy.startPlayLogic()

        var cover = item.cover
        val imagview = ImageView(context)
        imagview.scaleType = ImageView.ScaleType.CENTER_CROP
        if (cover != null) {
            LoadImage.loadMathImg(cover,imagview)
        }
        gsy.thumbImageView = imagview




        

    }
}